/*
********************************************************************************
* Copyright (C) 2021, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : log_base.h
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2021-12-17 version v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
                Compile command: make
********************************************************************************
*/
#include "sys_log.h"
#include "log_add_info.h"
#include "log_2_terminal.h"
#include "log.h"

static CLog *pLog = nullptr;
static CLogAddInfo *pLogAddInfo = nullptr;
static CLog2Terminal *pLog2Terminal = nullptr;

// 定制log：增加时间戳、终端打印
int sys_log(int level, const char *tag, const char *msg)
{
    // 保存至文件
    if (!pLog) {
        pLog = CLog::GetInstance();
    }

    // 在终端显示
    if (!pLog2Terminal) {
        pLog2Terminal = CLog2Terminal::GetInstance(pLog);
    }

    // 增加log调试信息: 时间戳、等级、标签
    if (!pLogAddInfo) {
        pLogAddInfo = CLogAddInfo::GetInstance(pLog2Terminal);
    }

    // 完成装饰的接口
    pLogAddInfo->SetLogLevel(level);
    pLogAddInfo->WriteLog(tag, msg);

    return 0;
}